﻿/*****************************************
 * File Name:   UIEvent.js
 * Author:      Chen Xin
 * Version:     1.0
 * Date:        2006-09-18
 * Description: 页面UI调用的事件函数
 *****************************************/

function openLegend() {

    var url = this.request.responseText;
    
    var legend = $("legend");
    //legend.
    
    if (legend.childNodes.length != 0 && legend.childNodes.length != 1) {
        var childNum = legend.childNodes.length;
        for (var i = 0;i < childNum; i++) {
            legend.removeChild(legend.firstChild);
        }
    }
    
    legend.className = "legend";
    
    var legendToolBar = document.createElement("div");
    legendToolBar.className = "legendtitlebar";
    
    var legendButton1 = document.createElement("span");
    legendButton1.className = "legendbutton";
    legendButton1.id = "close";
    legendButton1.alt = "关闭";
    legendButton1.onclick = closeLegend;

    var legendButton2 = document.createElement("span");
    legendButton2.className = "legendbutton";
    legendButton2.id = "min";
    
    var legendContent = document.createElement("div");
    legendContent.className = "legendcontent";
    
    var legendImg = document.createElement("img");
    legendImg.src = url;
    
    legendToolBar.appendChild(legendButton1);
    legendToolBar.appendChild(legendButton2);
    
    legendContent.appendChild(legendImg);
    
    legend.appendChild(legendToolBar);
    legend.appendChild(legendContent);
    GeoFunc.startUp();
}

function closeLegend() {
    var legend = $("legend");
    if (legend.children.length != 0 && legend.children.length != 1) {
        var childNum = legend.children.length;
        for (var i = 0;i < childNum; i++) {
            legend.removeChild(legend.first-child);
        }
    }
    legend.css("className",""); 
    GeoFunc.startUp();
    
}

var tidNodeValue;
var year = 2006;

function openPlanterInfo(originalRequest) {
    var planterInfo = $("planterInfo");
    if (planterInfo.childNodes.length !=0) {
        var childNum = planterInfo.childNodes.length;
        for (var i = 0; i < childNum; i++) {
            planterInfo.removeChild(planterInfo.firstChild);
        }
        planterInfo.style.visibility = "hidden";
    }
    
    var table = document.createElement("table");
    var tbody = document.createElement("tbody");
    table.setAttribute("id", "toolTipTable");
    table.appendChild(tbody);
    
//    var xmlDoc = this.request.responseXML.documentElement;
    var xmlDoc = originalRequest.responseXML.documentElement;
//    var dropDownBizValue = $("DropDownBiz").value;
     var dropDownBizValue = $("DropDownListBIZ").value;
    
    if (xmlDoc.childNodes.length < 3) {
        return;
    }
    switch (dropDownBizValue) {
        case "2":
            var tid = document.createTextNode(xmlDoc.getElementsByTagName("TID")[0].firstChild.nodeValue);
//            var field_area = document.createTextNode(xmlDoc.getElementsByTagName("FIELD_AREA")[0].firstChild.nodeValue + "亩");
            var fieldid = document.createTextNode(xmlDoc.getElementsByTagName("FIELD_ID")[0].firstChild.nodeValue);
            var field_area = document.createTextNode((xmlDoc.getElementsByTagName("AREA")[0].firstChild.nodeValue / 667).toFixed(2) + "亩");
            var field_locality = document.createTextNode(xmlDoc.getElementsByTagName("FIELD_LOCALITY")[0].firstChild.nodeValue);
            var planter_amount = document.createTextNode(xmlDoc.getElementsByTagName("PLANTER_AMOUNT")[0].firstChild.nodeValue);
            var account_year = document.createTextNode(xmlDoc.getElementsByTagName("ACCOUNT_YEAR")[0].firstChild.nodeValue);
            
            tidNodeValue = fieldid.nodeValue;
            year = account_year.nodeValue;
            
            tbody.insertRow(0);
            tbody.rows[0].insertCell(0);
            var imgPlanter = document.createElement("img");
            imgPlanter.setAttribute("src", "Picture/planter.gif");
            var hrefPlanter = document.createElement("a");
            hrefPlanter.setAttribute("href", "javascript:detailPlanterInfo()");
//            hrefPlanter.setAttribute("target", "_blank");
            var text = document.createTextNode("烟农信息");
            hrefPlanter.appendChild(text);
            tbody.rows[0].cells[0].appendChild(imgPlanter);
            tbody.rows[0].cells[0].appendChild(hrefPlanter);
            tbody.rows[0].insertCell(1);
            var imgX = document.createElement("img");
            imgX.setAttribute("src", "Picture/xblue_1.gif");
            imgX.onclick = removePlanterInfo;
            tbody.rows[0].cells[1].setAttribute("align", "right");
            tbody.rows[0].cells[1].appendChild(imgX);
            
            tbody.insertRow(1);
            tbody.rows[1].insertCell(0);
            tbody.rows[1].cells[0].appendChild(document.createTextNode("烟田编号"));
            tbody.rows[1].insertCell(1);
            tbody.rows[1].cells[1].appendChild(tid);
            
            tbody.insertRow(2);
            tbody.rows[2].insertCell(0);
            tbody.rows[2].cells[0].appendChild(document.createTextNode("规划面积"));
            tbody.rows[2].insertCell(1);
            tbody.rows[2].cells[1].appendChild(field_area);
            
            tbody.insertRow(3);
            tbody.rows[3].insertCell(0);
            tbody.rows[3].cells[0].appendChild(document.createTextNode("地理位置"));
            tbody.rows[3].insertCell(1);
            tbody.rows[3].cells[1].appendChild(field_locality);
            
            tbody.insertRow(4);
            tbody.rows[4].insertCell(0);
            tbody.rows[4].cells[0].appendChild(document.createTextNode("农户数量"));
            tbody.rows[4].insertCell(1);
            tbody.rows[4].cells[1].appendChild(planter_amount);
            
            planterInfo.appendChild(table);
            
            break;
        case "4":
            var tid = document.createTextNode(xmlDoc.getElementsByTagName("TID")[0].firstChild.nodeValue);
            var fieldid = document.createTextNode(xmlDoc.getElementsByTagName("FIELD_ID")[0].firstChild.nodeValue);
            var natural_type = document.createTextNode(xmlDoc.getElementsByTagName("NATURAL_TYPE")[0].firstChild.nodeValue);
//            var natural_area = document.createTextNode(xmlDoc.getElementsByTagName("NATURAL_AREA")[0].firstChild.nodeValue + "亩");
            
            var natural_area = document.createTextNode((xmlDoc.getElementsByTagName("AREA")[0].firstChild.nodeValue / 667).toFixed(2) + "亩");
            var natural_rate = document.createTextNode(xmlDoc.getElementsByTagName("NATURAL_RATE")[0].firstChild.nodeValue + "%");
            var natural_local = document.createTextNode(xmlDoc.getElementsByTagName("NATURAL_LOCAL")[0].firstChild.nodeValue);
            var account_year = document.createTextNode(xmlDoc.getElementsByTagName("ACCOUNT_YEAR")[0].firstChild.nodeValue);
            
            tidNodeValue = fieldid.nodeValue;
            year = account_year.nodeValue;
            
            tbody.insertRow(0);
            tbody.rows[0].insertCell(0);
            var imgPlanter = document.createElement("img");
            imgPlanter.setAttribute("src", "Picture/planter.gif");
            var hrefPlanter = document.createElement("a");
            hrefPlanter.setAttribute("href", "javascript:detailPlanterInfo()");
//            hrefPlanter.setAttribute("target", "_blank");
            var text = document.createTextNode("烟农信息");
            hrefPlanter.appendChild(text);
            tbody.rows[0].cells[0].appendChild(imgPlanter);
            tbody.rows[0].cells[0].appendChild(hrefPlanter);
            tbody.rows[0].insertCell(1);
            var imgX = document.createElement("img");
            imgX.setAttribute("src", "Picture/xblue_1.gif");
            imgX.onclick = removePlanterInfo;
            tbody.rows[0].cells[1].setAttribute("align", "right");
            tbody.rows[0].cells[1].appendChild(imgX);
            
            tbody.insertRow(1);
            tbody.rows[1].insertCell(0);
            tbody.rows[1].cells[0].appendChild(document.createTextNode("烟田编号"));
            tbody.rows[1].insertCell(1);
            tbody.rows[1].cells[1].appendChild(tid);
            
            tbody.insertRow(2);
            tbody.rows[2].insertCell(0);
            tbody.rows[2].cells[0].appendChild(document.createTextNode("受灾类型"));
            tbody.rows[2].insertCell(1);
            tbody.rows[2].cells[1].appendChild(natural_type);
            
            tbody.insertRow(3);
            tbody.rows[3].insertCell(0);
            tbody.rows[3].cells[0].appendChild(document.createTextNode("受灾面积"));
            tbody.rows[3].insertCell(1);
            tbody.rows[3].cells[1].appendChild(natural_area);
            
            tbody.insertRow(4);
            tbody.rows[4].insertCell(0);
            tbody.rows[4].cells[0].appendChild(document.createTextNode("受灾程度"));
            tbody.rows[4].insertCell(1);
            tbody.rows[4].cells[1].appendChild(natural_rate);
            
            tbody.insertRow(5);
            tbody.rows[5].insertCell(0);
            tbody.rows[5].cells[0].appendChild(document.createTextNode("地理位置"));
            tbody.rows[5].insertCell(1);
            tbody.rows[5].cells[1].appendChild(natural_local);
            
            planterInfo.appendChild(table);
            
            break;
        case "7":
            var well_number = document.createTextNode(xmlDoc.getElementsByTagName("WELL_NUMBER")[0].firstChild.nodeValue);
            var well_cubage = document.createTextNode(xmlDoc.getElementsByTagName("WELL_CUBAGE")[0].firstChild.nodeValue + "立方米");
            var irragate_area = document.createTextNode(xmlDoc.getElementsByTagName("IRRAGATE_AREA")[0].firstChild.nodeValue + "亩");
            var planter_no = document.createTextNode(xmlDoc.getElementsByTagName("PLANTER_NO")[0].firstChild.nodeValue);
            var planter_name = document.createTextNode(xmlDoc.getElementsByTagName("PLANTER_NAME")[0].firstChild.nodeValue);
            var planter_addr = document.createTextNode(xmlDoc.getElementsByTagName("PLANTER_ADDRESS")[0].firstChild.nodeValue);
            
            tbody.insertRow(0);
            tbody.rows[0].insertCell(0);
            tbody.rows[0].insertCell(1);
            var imgX = document.createElement("img");
            imgX.setAttribute("src", "Picture/xblue_1.gif");
            imgX.onclick = removePlanterInfo;
            tbody.rows[0].cells[1].setAttribute("align", "right");
            tbody.rows[0].cells[1].appendChild(imgX);

            
            tbody.insertRow(1);
            tbody.rows[1].insertCell(0);
            tbody.rows[1].cells[0].appendChild(document.createTextNode("水窖水池编号"));
            tbody.rows[1].insertCell(1);
            tbody.rows[1].cells[1].appendChild(well_number);
            
            tbody.insertRow(2);
            tbody.rows[2].insertCell(0);
            tbody.rows[2].cells[0].appendChild(document.createTextNode("水窖水池容积"));
            tbody.rows[2].insertCell(1);
            tbody.rows[2].cells[1].appendChild(well_cubage);
            
            tbody.insertRow(3);
            tbody.rows[3].insertCell(0);
            tbody.rows[3].cells[0].appendChild(document.createTextNode("可灌溉面积"));
            tbody.rows[3].insertCell(1);
            tbody.rows[3].cells[1].appendChild(irragate_area);
            
            tbody.insertRow(4);
            tbody.rows[4].insertCell(0);
            tbody.rows[4].cells[0].appendChild(document.createTextNode("农户编号"));
            tbody.rows[4].insertCell(1);
            tbody.rows[4].cells[1].appendChild(planter_no);
            
            tbody.insertRow(5);
            tbody.rows[5].insertCell(0);
            tbody.rows[5].cells[0].appendChild(document.createTextNode("农户姓名"));
            tbody.rows[5].insertCell(1);
            tbody.rows[5].cells[1].appendChild(planter_name);
            
            tbody.insertRow(6);
            tbody.rows[6].insertCell(0);
            tbody.rows[6].cells[0].appendChild(document.createTextNode("农户地址"));
            tbody.rows[6].insertCell(1);
            tbody.rows[6].cells[1].appendChild(planter_addr);
            
            planterInfo.appendChild(table);
            
            break;
        case "8":
            var oven_number = document.createTextNode(xmlDoc.getElementsByTagName("OVEN_NUMBER")[0].firstChild.nodeValue);
            var oven_type = document.createTextNode(xmlDoc.getElementsByTagName("OVEN_TYPE")[0].firstChild.nodeValue);
            var oven_capacity = document.createTextNode(xmlDoc.getElementsByTagName("OVEN_CAPACITY")[0].firstChild.nodeValue + "竿");
            var oven_area = document.createTextNode(xmlDoc.getElementsByTagName("OVEN_AREA")[0].firstChild.nodeValue + "亩");
            var planter_name = document.createTextNode(xmlDoc.getElementsByTagName("PLANTER_NAME")[0].firstChild.nodeValue);
            var planter_addr = document.createTextNode(xmlDoc.getElementsByTagName("PLANTER_ADDRESS")[0].firstChild.nodeValue);
            
            tbody.insertRow(0);
            tbody.rows[0].insertCell(0);
            tbody.rows[0].insertCell(1);
            var imgX = document.createElement("img");
            imgX.setAttribute("src", "Picture/xblue_1.gif");
            imgX.onclick = removePlanterInfo;
            tbody.rows[0].cells[1].setAttribute("align", "right");
            tbody.rows[0].cells[1].appendChild(imgX);
            
            tbody.insertRow(1);
            tbody.rows[1].insertCell(0);
            tbody.rows[1].cells[0].appendChild(document.createTextNode("烤房编号"));
            tbody.rows[1].insertCell(1);
            tbody.rows[1].cells[1].appendChild(oven_number);
            
            tbody.insertRow(2);
            tbody.rows[2].insertCell(0);
            tbody.rows[2].cells[0].appendChild(document.createTextNode("烤房类型"));
            tbody.rows[2].insertCell(1);
            tbody.rows[2].cells[1].appendChild(oven_type);
            
            tbody.insertRow(3);
            tbody.rows[3].insertCell(0);
            tbody.rows[3].cells[0].appendChild(document.createTextNode("烤房容量"));
            tbody.rows[3].insertCell(1);
            tbody.rows[3].cells[1].appendChild(oven_capacity);
            
            tbody.insertRow(4);
            tbody.rows[4].insertCell(0);
            tbody.rows[4].cells[0].appendChild(document.createTextNode("可烤面积"));
            tbody.rows[4].insertCell(1);
            tbody.rows[4].cells[1].appendChild(oven_area);
            
            tbody.insertRow(5);
            tbody.rows[5].insertCell(0);
            tbody.rows[5].cells[0].appendChild(document.createTextNode("农户姓名"));
            tbody.rows[5].insertCell(1);
            tbody.rows[5].cells[1].appendChild(planter_name);
            
            tbody.insertRow(6);
            tbody.rows[6].insertCell(0);
            tbody.rows[6].cells[0].appendChild(document.createTextNode("农户地址"));
            tbody.rows[6].insertCell(1);
            tbody.rows[6].cells[1].appendChild(planter_addr);
            
            planterInfo.appendChild(table);
            
            break;
        case "9":
            var tid = document.createTextNode(xmlDoc.getElementsByTagName("CANAL_NUMBER")[0].firstChild.nodeValue);
            var townid = document.createTextNode(xmlDoc.getElementsByTagName("TOWN_ID")[0].firstChild.nodeValue);
            var account_year = document.createTextNode(xmlDoc.getElementsByTagName("ACCOUNT_YEAR")[0].firstChild.nodeValue);
      //先注视这些,等服务更新后,解除注释
            var length = document.createTextNode(xmlDoc.getElementsByTagName("LEN")[0].firstChild.nodeValue);
          
            
            tbody.insertRow(0);
            tbody.rows[0].insertCell(0);
            tbody.rows[0].insertCell(1);
            var imgX = document.createElement("img");
            imgX.setAttribute("src", "Picture/xblue_1.gif");
            imgX.onclick = removePlanterInfo;
            tbody.rows[0].cells[1].setAttribute("align", "right");
            tbody.rows[0].cells[1].appendChild(imgX);
          
            tbody.insertRow(1);
            tbody.rows[1].insertCell(0);
            tbody.rows[1].cells[0].appendChild(document.createTextNode("管网沟渠编号"));
            tbody.rows[1].insertCell(1);
            tbody.rows[1].cells[1].appendChild(tid);
            
       
            
            tbody.insertRow(2);
            tbody.rows[2].insertCell(0);
            tbody.rows[2].cells[0].appendChild(document.createTextNode("所属乡镇编码"));
            tbody.rows[2].insertCell(1);
            tbody.rows[2].cells[1].appendChild(townid);
            
            tbody.insertRow(3);
            tbody.rows[3].insertCell(0);
            tbody.rows[3].cells[0].appendChild(document.createTextNode("业务年度"));
            tbody.rows[3].insertCell(1);
            tbody.rows[3].cells[1].appendChild(account_year);
            
            //先注视这些,等服务更新后,解除注释
            tbody.insertRow(4);
            tbody.rows[4].insertCell(0);
            tbody.rows[4].cells[0].appendChild(document.createTextNode("长度"));
            tbody.rows[4].insertCell(1);
            tbody.rows[4].cells[1].appendChild(length);
            
            planterInfo.appendChild(table);
            
            break;
       default:
//            var marea = document.createTextNode(xmlDoc.getElementsByTagName("MAREA")[0].firstChild.nodeValue + "亩");
            var marea = document.createTextNode((xmlDoc.getElementsByTagName("AREA")[0].firstChild.nodeValue / 667).toFixed(2) + "亩");
            
            tbody.insertRow(0);
            tbody.rows[0].insertCell(0);
            tbody.rows[0].insertCell(1);
            var imgX = document.createElement("img");
            imgX.setAttribute("src", "Picture/xblue_1.gif");
            imgX.onclick = removePlanterInfo;
            tbody.rows[0].cells[1].setAttribute("align", "right");
            tbody.rows[0].cells[1].appendChild(imgX);
            
            tbody.insertRow(1);
            tbody.rows[1].insertCell(0);
            tbody.rows[1].cells[0].appendChild(document.createTextNode("面积"));
            tbody.rows[1].insertCell(1);
            tbody.rows[1].cells[1].appendChild(marea);
            
            planterInfo.appendChild(table);
            
            break;
    }
    
    var eventX = xmlDoc.getElementsByTagName("PointX")[0].firstChild.nodeValue;
    var eventY = xmlDoc.getElementsByTagName("PointY")[0].firstChild.nodeValue;
    
    planterInfo.style.left = eventX - 10;
    planterInfo.style.top = eventY - 10;
//    planterInfo.innerText = "X坐标：" + eventX + ";Y坐标：" + eventY;
    planterInfo.style.visibility = "visible";
    

}

function detailPlanterInfo() {
    //var url = "http://172.16.1.239/CaitTM/PageFor3S/FieldPlanterListFor3S.aspx?FieldNo=" + tidNodeValue + "&AccountYear=" + year;
    var url = "http://168.160.192.50/mapserv3/PageFor3S/Planterlist.aspx?FieldNO=" + tidNodeValue;
    window.open(url, "烟田农户列表", "height=510,width=600,top=20,left=20,resizable=no");
}

function removePlanterInfo() {
    if (planterInfo.childNodes.length != 0) {
        var childNum = planterInfo.childNodes.length;
        for (var i = 0;i < childNum; i++) {
            planterInfo.removeChild(planterInfo.firstChild);
        }
    }
    planterInfo.style.visibility = "hidden";
}